define(['jquery', 'bootstrap', 'utilback', 'table', 'form', 'myfileinput','ztree'], function($, undefined, Utilback, Table, Form, myfileInput) {

	var Controller = {
		config: {
			get_url: '/user/read/detail', // 获取用户详情
		},
		init: function() {
			// 初始化表格参数配置
			Table.api.init({
				singleSelect: true,
				extend: {
					index_url: './json/trackCarRecord.json', // 查询列表
					add_url: 'trackCarRecordfoAdd.html', // 新增页面
					edit_url: 'trackCarRecordfoAdd.html', // 修改页面
					del_url: '/trackCarRecord', // 删除
					multi_url: '/trackCarRecord',
					guidIn_url: 'driverGuidIn.html', //添加导入页面
					img_url:'driverInfoImg.html',
					record_url:'trackCarRecordDetile.html',//履历簿的地址
					driver_url:'driverInfo.html',//司机信息
					
				}
			});
			var table = $("#userTable");

			// 初始化表格
			table.bootstrapTable({
				url: $.fn.bootstrapTable.defaults.extend.index_url,
				method: 'get',
				columns: [
					[{
							field: 'state',
							checkbox: true,
						},
						{
							field: 'id',
							title: 'ID'
						},
						{
							field: 'wagonNumber',
							title: '车号',
							formatter : function (value,row,index) {
								return Table.api.formatter.addtabs(value,row,index);
							}},
						{
							field: 'dept',
							title: "部门"
						},
						{
							field: 'storageLife',
							title: "保存年限"
						},
						{
							field: 'deviceName',
							title: "设备名称"
						},
						{
							field: 'productionCertificate',
							title: "生产许可证"
						},
						{
							field: 'manufactureFactory',
							title: "生产厂家"
						},
						{
							field: 'models',
							title: '规格型号'
						}, {
							field: 'factoryNumber',
							title: "出厂编号"
						},
						{
							field: 'factoryDate',
							title: "出厂日期"
						},
						{
							field: 'equipmentNumber',
							title: "设备编号"
						},
						{
							field: 'status',
							title: "状态"
						}, {
							field: 'picture',
							title: "图片",
							events: Table.api.events.operate,
							formatter : function (value,row,index) {
								return Table.api.formatter.addtabs(value,row,index,$.fn.bootstrapTable.defaults.extend.img_url);
							}},
						{
							field: 'operate',
							title: __('Operate'),
							events: Table.api.events.operate,
							formatter: function(value, row, index) {
								return Table.api.formatter.operate.call(this, value, row, index, table);
							}
						},
						{
							field:'link',
							title:'链接',
							formatter : function (value,row,index) {
								return Table.api.formatter.addtabs2(value,row,index);
							}
						}
						
					]
				]
			});

			// 为表格绑定事件
			Table.api.bindevent(table);
			// 添加履历簿
			$('.btn-record').on('click',function(){
				var ids = Table.api.selectedids(table);
				var options = table.bootstrapTable('getOptions');
                var url = options.extend.record_url + (options.extend.record_url.match(/(\?|&)+/) ? "&id=" : "?id=") + ids.join(",") + '&t=A';
                window.open(url);
			})
		},

		edit: function() { // 初始化编辑页面
			    Util.api.initSelectTree({
                checkParent: true,
                parentEle: 'department',
                url: './json/list.json',
                data: JSON.stringify({keyword:''}),
                method:'get',
                resetData: function(data) {
                   for(var i=0;i<data.length;i++) {
                       if(data[i].leaf == 0) {
                           data[i]['open'] = true;
                       }
                       data[i]['pId'] = data[i].parentId;
                       data[i]['name'] = data[i].deptName;
                   }
                   return data;
                }
            });
            var id = Util.api.query('id');
            var t = Util.api.query('t');
            if(id && t === 'U') {
                Form.api.fill($('#edit-form'), Controller.config.get_url, id, function(data) {
                });
            }
            // 跳转链接
               $('[href="#dic"]').on('click',function(){
               		$().Util.api.open('analysis.html');
               });
        },
		update: function() {
			Form.api.bindevent($("form[role=form]"));
			Util.api.ajax({
				type: 'GET',
				url: '/user/read/current'
			}, function(data) {
				$('#edit-form').autofill(data);
			});
		}
	};
	return Controller;

	function changeAgentContent() {
		document.getElementById("inputFileAgent").value = document.getElementById("inputFile").value;
	}
});